//===- InitAllPasses.h - MLIR Passes Registration ---------------*- C++ -*-===//
//
// Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
//
// This file defines a helper to trigger the registration of all dialects and
// passes to the system.
//
//===----------------------------------------------------------------------===//

#ifndef BISHENGIR_INITALLPASSES_H
#define BISHENGIR_INITALLPASSES_H

#include "bishengir/Config/bishengir-config.h"
#include "bishengir/Conversion/Passes.h"
#include "bishengir/Dialect/Annotation/Transforms/Passes.h"
#include "bishengir/Dialect/HACC/Transforms/Passes.h"
#include "bishengir/Dialect/HFusion/Pipelines/Passes.h"
#include "bishengir/Dialect/HFusion/Transforms/Passes.h"
#include "bishengir/Dialect/HIVM/Pipelines/ConvertToHIVMPipeline.h"
#include "bishengir/Dialect/HIVM/Transforms/Passes.h"
#include "bishengir/Dialect/MemRef/Transforms/Passes.h"
#include "bishengir/Dialect/SCF/Transforms/Passes.h"
#include "bishengir/Dialect/Symbol/Transforms/Passes.h"
#include "bishengir/Dialect/Tensor/Transforms/Passes.h"
#include "bishengir/Tools/bishengir-compile/PassPipeline.h"
#include "bishengir/Transforms/Passes.h"

#if MLIR_ENABLE_EXECUTION_ENGINE
#include "bishengir/ExecutionEngine/Passes.h"
#endif

#if BISHENGIR_ENABLE_TORCH_CONVERSIONS
#include "bishengir/Dialect/Torch/Pipelines/Passes.h"
#include "bishengir/Dialect/Torch/Transforms/Passes.h"
#include "torch-mlir-dialects/Dialect/TMTensor/Transforms/Passes.h"
#include "torch-mlir/Conversion/Passes.h"
#include "torch-mlir/Conversion/TorchOnnxToTorch/Passes.h"
#include "torch-mlir/Dialect/Torch/Transforms/Passes.h"
#include "torch-mlir/Dialect/TorchConversion/Transforms/Passes.h"
#endif

namespace bishengir {

// This function may be called to register the bishengir-specific MLIR passes
// with the global registry.
inline void registerAllPasses() {
  // Conversion passes
  bishengir::registerConversionPasses();

  // Dialect passes
  mlir::annotation::registerAnnotationPasses();
  mlir::hfusion::registerHFusionPasses();
  mlir::hivm::registerHIVMPasses();
  mlir::memref::registerBiShengIRMemRefPasses();
  mlir::tensor::registerBiShengIRTensorPasses();
  mlir::scf::registerBiShengIRSCFPasses();
  mlir::hacc::registerHACCPasses();
  mlir::symbol::registerSymbolPasses();

  // Transforms passes
  bishengir::registerBiShengIRTransformPasses();

#if BISHENGIR_ENABLE_TORCH_CONVERSIONS
  bishengir::registerConvertTorchToHFusion();
  mlir::torch::registerLiteralDataTypeCast();
  mlir::torch::registerTorchPasses();
  mlir::torch::registerTorchConversionPasses();
  mlir::torch::registerConversionPasses();
  mlir::torch::onnx_c::registerTorchOnnxToTorchPasses();
  mlir::torch::TMTensor::registerPasses();
#endif

  // Dialect passes that aren't generated by tblgen
  mlir::hfusion::registerAutoScheduleInterpreterPass();
  mlir::hfusion::registerEraseAutoSchedulePass();

  // Dialect pipelines
  bishengir::registerBiShengIRCompilePass();
  mlir::hivm::registerConvertToHIVMPipelines();
  mlir::hfusion::registerLowerHFusionPipelines();

#if MLIR_ENABLE_EXECUTION_ENGINE
  mlir::execution_engine::registerExecutionEnginePasses();
  mlir::execution_engine::registerAllPipelines();
#endif

#if BISHENGIR_ENABLE_TORCH_CONVERSIONS
  bishengir::registerTorchToHFusionPipelines();
#endif
}

} // namespace bishengir

#endif // BISHENGIR_INITALLPASSES_H
